package com.jinbo.sxzq;

import android.app.Activity;
import android.content.Intent;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;

import androidx.annotation.Nullable;

import java.util.ArrayList;
import java.util.List;

public class LevelSelectActivity extends Activity {
    private List<LevelSelectItem> levelSelectItemList = new ArrayList<>();
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_levelselect);
        initListItem();
        LevelSelectAdapter levelSelectAdapter = new LevelSelectAdapter(LevelSelectActivity.this,
                R.layout.adapter_levelselect,levelSelectItemList);
        ListView listView = (ListView) findViewById(R.id.levelselect_listview);
        listView.setAdapter(levelSelectAdapter);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                LevelSelectItem levelSelectItem = levelSelectItemList.get(position);
                int level = levelSelectItem.getLevel();
                Intent intent = new Intent();
                intent.setFlags(level);
                intent.setClass(LevelSelectActivity.this,GameActivity.class);
                Toast.makeText(LevelSelectActivity.this,levelSelectItem.getLevelName(),Toast.LENGTH_SHORT).show();
                startActivity(intent);
            }
        });
    }

    private void initListItem(){//加载关卡内容
        for(int i = 1 ; i < 13 ; i++){
            LevelSelectItem levelSelectItem =  new LevelSelectItem("测试" + i,i);
            levelSelectItemList.add(levelSelectItem);
        }
    }
}